package com.example.beza;import android.app.Activity;
import android.os.Bundle;
import android.view.View; 
import android.widget.*; 

public class beza extends Activity {
       
       Button button1, button2;
       EditText text1, text2;
       CharSequence t = null ;
       String str, binaryString;
       
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       text1 = (EditText)findViewById(R.id.text1);
       button1 = (Button)findViewById(R.id.button1);
       
       text2 = (EditText)findViewById(R.id.text2);
       button2 = (Button)findViewById(R.id.button2);
       
       button1.setOnClickListener(new clicker());
       button2.setOnClickListener(new clicker());
   }
   
   class clicker implements Button.OnClickListener
   {
           public void onClick(View v)
           {
                   if(v == button1){
                           //text1.setText("Welcome");
                           t = text1.getText();
                           
                           str = t.toString();
                           
                           binaryString = "";
                           String leadingZero = "";
                           int j;
                           
                           System.out.println("Check whether it is aloha " + str);
                           for(int i=0; i<str.length(); i++){
                                   char c = str.charAt(i);
                                  
               					j = Integer.toBinaryString(c).length();
            					while(j < 8){
            						leadingZero += "0";
            						j++;
            					}
            					
                                   binaryString +=  leadingZero + Integer.toBinaryString(c);
                                   
                           }
                           System.out.println("Text in textbox 1 is " + str);
                           text2.setText(binaryString);
                   }
                   
                   if(v == button2){
                           str = text2.getText().toString();
                           
                           byte[] bin = str.getBytes();
                           
                           System.out.println("bin = " + bin);
                           
                           System.out.println("Binary String = " + binaryString);
                           System.out.println("Text in textbox 2 is " + text2.getText().toString());
                   }

           }
   }
}